﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(AudioSource))]
public class AudioVariance : MonoBehaviour
{
    public float pitchVariance = 0.05f;
    public float volumeVariance = 0.1f;
    public bool mayFlip = false;
    
    private AudioSource _source;
    // Start is called before the first frame update
    void Awake()
    {
        _source = GetComponent<AudioSource>();
    }

    void Start()
    {
        
        _source.pitch = _source.pitch + Random.Range(-pitchVariance, pitchVariance);
        if (mayFlip && Random.value > 0.5f)
        {
            _source.pitch = -_source.pitch;
            _source.time = _source.clip.length - 0.01f;
        }
        _source.volume = _source.volume + Random.Range(-volumeVariance, volumeVariance);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
